/* component */
import BizWorkWxChatToolBarDialog from '@src/component/business/BizWorkWxChatToolBarDialog/BizWorkWxChatToolBarDialog.tsx'
/* enum */
import ComponentNameEnum from '@model/enum/ComponentNameEnum'
/* util */
import fastCall from '@src/component/util/fastCall'
import { destroyComponent } from '@src/util/dom'
import { mount } from '@src/util/vue'
/* vue */
import VC from '@model/VC'
import { Component, Ref } from 'vue-property-decorator'
import Vue, { VueConstructor } from 'vue'

/**
 * @description: 初始化企业微信聊天工具栏弹窗
 * @return {Vue} vue组件实例
*/
export function initWorkWxChatToolBarDialogDialog(): Vue {
  @Component({
    components: {
      [ComponentNameEnum.BizWorkWxChatToolBarDialog]: BizWorkWxChatToolBarDialog
    }
  })
  class BizWorkWxChatToolBarDialogHOC extends VC {
    
    /* 企业微信聊天工具栏弹窗组件 */
    @Ref() BizWorkWxChatToolBarDialogComponent!: BizWorkWxChatToolBarDialog
    
    /** 销毁 */
    private destroy() {
      setTimeout(() => destroyComponent(this), 1500)
    }
    
    mounted() {
      // 打开企业微信聊天工具栏弹窗
      this.BizWorkWxChatToolBarDialogComponent?.outsideShow()
    }
    
    render() {
      return (
        <biz-work-wx-chat-toolbar-dialog
          ref='BizWorkWxChatToolBarDialogComponent'
          onDestroy={() => this.destroy()}
        >
        </biz-work-wx-chat-toolbar-dialog>
      )
    }
  }
  
  return mount(BizWorkWxChatToolBarDialogHOC, ComponentNameEnum.BizWorkWxChatToolBarDialogHOC) as Vue
}

const BizVersionLimitDialogComponent = {
  install(vue: VueConstructor) {
    // 注册到全局组件
    vue.component(ComponentNameEnum.BizWorkWxChatToolBarDialog, BizWorkWxChatToolBarDialog)
    // 注册快速调用方法
    fastCall(vue, 'biz', { initWorkWxChatToolBarDialogDialog })
  },
  namespace: 'biz',
  props: { initWorkWxChatToolBarDialogDialog }
}

export default BizVersionLimitDialogComponent